package com.hzy.so.controller;

import com.hzy.common.entities.CommonResult;
import com.hzy.sample.entities.Payment;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author hzy
 * @since 2022/3/3 22:19
 */
@RequestMapping("/payment")
@RestController
public class PaymentController {

    @Value("${server.port}")
    private String serverPort;

    public static final Map<String, Payment> DATA = new HashMap<>();
    static {
        DATA.put("1", new Payment("1", "aaaaaaaaaaaaaa"));
        DATA.put("2", new Payment("2", "bbbbbbbbbbbbbb"));
        DATA.put("3", new Payment("3", "cccccccccccccc"));
    }

    @RequestMapping("/load/{id}")
    public CommonResult<Payment> load(@PathVariable("id") String id){
        Payment payment = DATA.get(id);
        if (null == payment){
            throw new IllegalArgumentException(id);
        }
        return new CommonResult<>(1, HttpStatus.OK.toString() + " from " + serverPort, payment);
    }

}
